home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 …ember: Reference Library / Dev.CD Dec 97 RL.toast / What's New / Tool Chest / Testing & Debugging / Virtual User / Examples / Example Scripts / DrawShapesStress.vu < prev    next >
Encoding:
Text File  |  1997-10-15  |  12.5 KB  |  406 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        DrawShapes.vu 
  3. #
  4. #    Contains:    A test script for DrawShapesVU, the MacApp DrawShapes example program which 
  5. #                has been built with the Assistance Module for MacApp.  The script selects
  6. #                a random shape to draw, draws it to a random size in a random location within
  7. #                the window, colors and shades it randomly, and then moves it to a random location in
  8. #                the window.  It selects a random editing operation after every "shapesPerEdit" 
  9. #                shapes are drawn. A number of shapes equal to the global variable "numShapes" 
  10. #                (set to a default of 15) is drawn before the script stops.
  11. #
  12. #                DrawShapesVU can run critically low on memory if the partition size is too
  13. #                small.  DrawShapesVU may not have enough memory to even exit in these cases.
  14. #                Because of this, this script will simply detect the situation and abort the
  15. #                script.
  16. #
  17. #                The theRandomSeed script parameter specifies the variable used to seed Virtual 
  18. #                User's random number generator.  By using the same theRandomSeed variable on 
  19. #                the same setup, this script has the ability to play back its actions at a future 
  20. #                time.
  21. #
  22. #
  23. #    Requirements:    In order for the script to run properly, the target should have the 
  24. #                    DrawShapesVU MacApp demo program version 1.0d1 either all ready running
  25. #                    or able to be located by System 7 Finder's "Find" command.  Versions of
  26. #                    DrawShapes that have not been built with the MacApp assistance module will
  27. #                    not work properly.  For best results use the version included in the 
  28. #                    Virtual User 2.0 package.
  29. #                            
  30. #
  31. #    Written by:    Jim Schneider
  32. #
  33. #    Copyright:    © 1990-1992 by Apple Computer, Inc., all rights reserved.
  34. #
  35. #    Change History:
  36. #
  37. #         8/14/92    DGG        RandomSeed added.
  38. #         8/13/92    DGG        "retrace" script building removed in prep. for RandomSeed
  39. #                            DSOutOfMemory check added.
  40. #         7/7/92        DGG        cleanup for Virtual User 2.0
  41. #         8/15/90    JAS        added echo option to build "retrace" script as output
  42. #         8/15/90    JAS        took out window scrolling, inserted window drag to known location
  43. #         5/15/90    JAS        take out infinite loop.    
  44. #         5/2/90        JAS        creation
  45. #
  46.  
  47. Libraries "UtilityTasks.vulib";
  48.  
  49. (************************************************************************************
  50. * Task SelectPalletteTool()
  51. *    Select the DrawShapes tool from the pallette
  52. ************************************************************************************)
  53. task SelectPalletteTool(theTool) 
  54. begin
  55.     global gWindGRect;
  56.     
  57.     x:=gWindGRect[1]-20;
  58.     y:=gWindGRect[2]+20+(40*(theTool-1));
  59.     move a: {x,y};
  60.     click;
  61. end;
  62.  
  63.  
  64. (************************************************************************************
  65. * Task HandleColorPicker()
  66. *    Pick a random color from the color picker dialog.
  67. ************************************************************************************)
  68. task HandleColorPicker() 
  69. begin
  70.     global gMaxScrollValue;
  71.     global gRelColorPickerCenter;
  72.     global gPickerRadius;    
  73.     
  74.     match[window o:1 r:?colorPickerWingRect];
  75.     #scrollValue := random(1,gMaxScrollValue);
  76.     #scroll [scrollBar w:[window o:1]] a:{scrollValue,gMaxScrollValue};
  77.     wait(1);
  78.     colorPickerCenter := {gRelColorPickerCenter[1] + colorPickerWingRect[1],gRelColorPickerCenter[2] + colorPickerWingRect[2]};
  79.     x_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
  80.     y_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
  81.     while ((x_offset*x_offset) + (y_offset*y_offset) > gPickerRadius*gPickerRadius) 
  82.     begin
  83.         x_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
  84.         y_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
  85.     end;
  86.     x:=colorPickerCenter[1]+x_offset;
  87.     y:=colorPickerCenter[2]+y_offset;
  88.     move a:{x,y};
  89.     wait(1);    
  90.     click;    
  91.     select [button t:'OK' w:[window o:1]]!;
  92. end;
  93.     
  94.  
  95. (************************************************************************************
  96. * Task ColorShape()
  97. *    Color the selected shape a random color from Colors menu.  Screen out the '---' 
  98. *    item.
  99. ************************************************************************************)
  100. task ColorShape() 
  101. begin
  102.     global gNumColors;
  103.     global gColorSepItem;
  104.     global gPickColorItem;    
  105.     
  106.     theColor := random(1,gNumColors);
  107.     if (theColor = gColorSepItem) 
  108.         while (theColor = gColorSepItem) 
  109.             theColor := random(1,gNumColors);    
  110.     select [menuitem m:[menu t:"Colors"] o:theColor];
  111.     if (theColor = gPickColorItem)
  112.         HandleColorPicker();
  113. end;
  114.  
  115. (************************************************************************************
  116. * Task ShadeShape()
  117. *    Shade the selected shape a random shade from the Shades menu.
  118. ************************************************************************************)
  119. task ShadeShape() 
  120. begin
  121.     global gShadeMenuPosn;
  122.     global gShadeCellSize;    
  123.     
  124.     theRow := random(1,2);
  125.     theColumn := random(0,2);
  126.     x:=gShadeMenuPosn[1];
  127.     y:=gShadeMenuPosn[2];
  128.     move a:{x,y};
  129.     pressMouse;    
  130.     wait(1);
  131.     x:=gShadeCellSize*theColumn;
  132.     y:=gShadeCellSize*theRow;
  133.     move r: {x,y};            
  134.     wait(1);
  135.     releaseMouse;    
  136. end;
  137.  
  138.  
  139. (************************************************************************************
  140. * Task TestShapeDrawn()
  141. *    Return true if a shape was just drawn (we know this by seeing if the 'Colors' 
  142. *    menu is enabled).  Otherwise, return false.
  143. ************************************************************************************)
  144. task TestShapeDrawn() 
  145. begin
  146.     match[menu t:'Colors' e:?enabled]!;
  147.     return(enabled);
  148. end;
  149.  
  150.  
  151. (************************************************************************************
  152. * Task DrawShape()
  153. *    Select a random shape to draw from pallette and draw it at a random position.  
  154. *    Size it to a random size.  Return the coordinates of the shape's Rectangle.
  155. ************************************************************************************)
  156. task DrawShape()
  157. begin
  158.     global gRect;
  159.     global gOval;
  160.     global gThickGRect;                        
  161.     global gWindGRect;
  162.     
  163.     prevSpeed := mouseSpeed(4);
  164.     theTool := random(gRect,gThickGRect);    
  165.     SelectPalletteTool(theTool);
  166.     xCoord1 := random(gWindGRect[1],gWindGRect[3]);
  167.     yCoord1 := random(gWindGRect[2],gWindGRect[4]);
  168.     move a: {xCoord1,yCoord1};
  169.     wait(1);    
  170.     pressMouse;
  171.     xCoord2 := random(gWindGRect[1],gWindGRect[3]);
  172.     yCoord2 := random(gWindGRect[2],gWindGRect[4]);
  173.     move a: {xCoord2,yCoord2};
  174.     wait(1);
  175.     releaseMouse;
  176.     mouseSpeed(prevSpeed);
  177.     return({xCoord1,yCoord1,xCoord2,yCoord2});
  178. end;
  179.  
  180.  
  181. (************************************************************************************
  182. * Task MoveShape()
  183. * Move the most current shape to a random position.  Pass back new shape gRectangle.
  184. ************************************************************************************)
  185. task MoveShape()
  186. begin
  187.     global gArrow;
  188.     global gWindGRect;
  189.     global gShapegRect;
  190.     
  191.     xCoord := random(gWindGRect[1],gWindGRect[3]);
  192.     yCoord := random(gWindGRect[2],gWindGRect[4]);
  193.     SelectPalletteTool(gArrow);
  194.     x:=(gShapegRect[1]+gShapegRect[3])/2;
  195.     y:=(gShapegRect[2]+gShapegRect[4])/2;
  196.     move a: {x,y};
  197.     pressMouse;    
  198.     wait(1);    
  199.     move a: {xCoord,yCoord};
  200.     wait(1);
  201.     releaseMouse;
  202.     shapeWidth := gShapegRect[3]-gShapegRect[1];
  203.     shape_height := gShapegRect[4] - gShapegRect[2];
  204.     return({xCoord-(shapeWidth/2),yCoord-(shape_height/2),xCoord+(shapeWidth/2),yCoord+(Shape_height/2)});
  205. end;
  206.     
  207.  
  208. (************************************************************************************
  209. * Task DoSomeEditing()
  210. *    Select random item from edit menu and then possibly do something else, depending 
  211. *    on what item was selected.  Screen out the "---" items.
  212. ************************************************************************************)
  213. task DoSomeEditing()
  214. begin
  215.     global gShapegRect;
  216.     global gArrow;
  217.     global gNumEditItems;
  218.     global gUndoItem;
  219.     global gEditSepItem1;
  220.     global gCutItem;
  221.     global gCopyItem;
  222.     global gPasteItem;
  223.     global gClearItem;
  224.     global gSelectAllItem;
  225.     global gEditSepItem2;
  226.     global gShowClipboardItem;
  227.     
  228.     theItem := random(1,gNumEditItems);
  229.     while (not ((theItem = gEditSepItem1) or (theItem = gEditSepItem2)))
  230.         theItem := random(1,gNumEditItems);
  231.     match [menuitem m:[menu t:'Edit'] o:theItem e:?enabled];
  232.     while (not enabled)
  233.     begin
  234.         theItem := random(1,gNumEditItems);
  235.         match [menuitem m:[menu t:'Edit'] o:theItem e:?enabled];
  236.     end;
  237.     select [menuitem m:[menu t:'Edit'] o:theItem]!;
  238.     if ((theItem = gCutItem) or (theItem = gCopyItem)) 
  239.     begin
  240.         select [menuitem t:'Paste' m:[menu t:'Edit']]!;
  241.     end;
  242.     else if (theItem = gSelectAllItem) 
  243.     begin    # move everything 50 pixels right or left, up or down
  244.         xCoord := 50 - random(1,100);
  245.         yCoord := 50 - random(1,100);
  246.         SelectPalletteTool(gArrow);
  247.         x := (gShapegRect[1]+gShapegRect[3])/2;
  248.         y := (gShapegRect[2]+gShapegRect[4])/2;
  249.         move a: {x,y};
  250.         pressMouse; 
  251.         wait(1); 
  252.         move r: {xCoord,yCoord};
  253.         wait(1);
  254.         releaseMouse;
  255.     end;
  256.     else if (theItem = gShowClipboardItem) 
  257.     begin
  258.         wait(1);
  259.         close [window o:1];
  260.     end;
  261. end;
  262.     
  263.         
  264. (************************************************************************************
  265. * Task CleanUpWindow()
  266. *    Clean up the DrawShapes window
  267. ************************************************************************************)
  268. task CleanUpWindow()
  269. begin
  270.     
  271.     match [menuitem t:"Select All" m:[menu t:"Edit"] e:?enabled];
  272.     if (enabled) 
  273.     begin
  274.         select[menuitem t:"Select All" m:[menu t:"Edit"]];
  275.         select[menuitem t:"Clear" m:[menu t:"Edit"]];
  276.     end;
  277. end;
  278.  
  279.  
  280. (************************************************************************************
  281. * Task GetWindCntgRect()
  282. *    Get the gRectangle representing the DrawShape's window content region
  283. ************************************************************************************)
  284. task GetWindCntgRect()
  285. begin
  286.     global gPixLeft;
  287.     global gPixTop;        
  288.     global gPixRight;
  289.     global gPixBottom;
  290.     
  291.     match [window o:1 r:?windowGRect]!;
  292.     return({windowGRect[1]+gPixLeft,windowGRect[2]+gPixTop,windowGRect[3]-gPixRight,windowGRect[4]-gPixBottom});
  293. end;
  294.  
  295. (************************************************************************************
  296. * Task DSOutOfMemory()
  297. *    Test to see if an out of memory dialog is present.
  298. ************************************************************************************)
  299. task DSOutOfMemory()
  300. begin
  301.     if match [window s:dialog o:1]
  302.     begin
  303.         if (match [icon t:'' o:3 e:false]) or 
  304.             (match [staticText t:'Memory space is low.  Some commands may be disabled.'])
  305.         begin
  306.             return true;
  307.         end;
  308.     end;
  309.     else
  310.         return false;
  311. end;
  312.  
  313. ##### MAIN EXECUTION STARTS HERE  ######
  314. (************************************************************************************
  315. * The variable numShapes determines number of shapes drawn.
  316. * ShapesPerEdit determines the number of shapes to draw before a random editing 
  317. *    operation takes place.
  318. * The theRandomSeed parameter specifies the variable to seed the random number
  319. *    generator.  By using the same theRandomSeed variable on the same setup, this
  320. *    script has the ability to play back its actions at a future time.
  321. ************************************************************************************)
  322. script DrawShapesMain(numShapes := 15, shapesPerEdit := 3, theRandomSeed := undefined)
  323. begin
  324.     # set up the random seed process
  325.     if IsUndefined(theRandomSeed)
  326.         theRandomSeed := Random();
  327.     RandomSeed(theRandomSeed);
  328.     println "### DrawShapesVU Random Seed: ",theRandomSeed;
  329.  
  330.     if (not LaunchApp("DrawShapesVU"))
  331.     begin
  332.         println "### Unable to launch DrawShapesVU!!!∂n### Script aborting!";
  333.         exit;
  334.     end;
  335.  
  336.     # indices into pallette
  337.     gArrow                    := 1;
  338.     gRect                    := 2;
  339.     gOval                    := 3;
  340.     gThickGRect                := 4;
  341.  
  342.     # misc. globals
  343.     gColorSepItem             := 8;
  344.     gPickColorItem             := 9;
  345.     gMaxScrollValue         := 32767;
  346.     gRelColorPickerCenter    := {293,137};
  347.     gPickerRadius             := 100;
  348.     gShadeMenuPosn            := {125,10};
  349.     gShadeCellSize            := 25;
  350.  
  351.     # pixels between window gRect and content gRect
  352.     gPixTop                    := 21;
  353.     gPixLeft                := 41;
  354.     gPixBottom                := 17;
  355.     gPixRight                := 17;
  356.  
  357.     #edit menu items
  358.     gNumEditItems             := 9;
  359.     gUndoItem                := 1;
  360.     gEditSepItem1            := 2;
  361.     gCutItem                := 3;
  362.     gCopyItem                := 4;
  363.     gPasteItem                := 5;
  364.     gClearItem                := 6;
  365.     gSelectAllItem            := 7;
  366.     gEditSepItem2            := 8;
  367.     gShowClipboardItem        := 9;
  368.  
  369.     match [menu t:"Colors" i:?itemList]!;
  370.     gNumColors := card(itemList);        # get number of items in Colors menu
  371.  
  372.     match [menu t:"edit" i:?itemList]!;
  373.     gNumEditItems := card(itemList);    # get number of items in Edit menu;
  374.  
  375.     CloseAllWindows();
  376.     select [menuItem t:"New" m:"File"];
  377.     CleanUpWindow();
  378.  
  379.     # this is done to ensure that absolute moves in output script will match those 
  380.     # made in running this script
  381.     println "### Now performing DrawShapesVU Stress Test!";
  382.     drag [window o:1] a:{5,25};            
  383.  
  384.     gWindGRect := GetWindCntgRect();    # get window's content gRectangle
  385.  
  386.     for i := 1 to numShapes
  387.     begin
  388.         if DSOutOfMemory()
  389.         begin
  390.             println "### DrawShapesVU is critically out of memory!";
  391.             println "### Aborting script!";
  392.             exit;
  393.         end;
  394.         
  395.         gShapegRect := DrawShape();
  396.         if TestShapeDrawn()
  397.         begin
  398.             ColorShape();
  399.             ShadeShape();
  400.             gShapegRect := MoveShape();
  401.             if ((i mod shapesPerEdit) = 0)
  402.                 DoSomeEditing();
  403.         end;
  404.     end;
  405.  
  406. end; # DrawShapesStress.vu